home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / make / icmake-6.000 / icmake-6 / icmake / exec / funfield.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-08  |  1.2 KB  |  62 lines

  1. /*
  2. \funcref{fun\_fields}{void fun\_fields ()}
  3.     {}
  4.     {}
  5.     {}
  6.     {fun\makelist(), addtolist()}
  7.     {funfield.c}
  8.     {
  9.  
  10.         This function is executed upon an opcode {\em op\_fields}. The last
  11.         pushed string is converted to a list, by splitting it according to the
  12.         separators which are found in the one-but-last pushed string.
  13.  
  14.         When the separator-string is empty, then the string to split is split
  15.         into separate characters.
  16.  
  17.     }
  18.  
  19. */
  20.  
  21. #include "icm-exec.h"
  22.  
  23. void fun_fields ()
  24. {
  25.     register char
  26.         *string,
  27.         *sep,
  28.         *cp;
  29.     char
  30.         buf [2];
  31.  
  32.     buf [1] = '\0';
  33.  
  34.     string = stack [sp].vu.i->ls.str;
  35.     sep    = stack [sp - 1].vu.i->ls.str;
  36.  
  37.     reg = newvar (e_list);
  38.  
  39.     if (*string)
  40.     {
  41.         string = xstrdup (string);
  42.         if (*sep)
  43.         {
  44.             if ( (cp = strtok (string, sep)) )
  45.             {
  46.                 reg = addtolist (reg, cp);
  47.                 while ( (cp = strtok (NULL, sep)) )
  48.                     reg = addtolist (reg, cp);
  49.             }
  50.         }
  51.         else
  52.         {
  53.             for (cp = string; *cp; cp++)
  54.             {
  55.                 buf [0] = *cp;
  56.                 reg = addtolist (reg, buf);
  57.             }
  58.         }
  59.         xrealloc (string, 0);
  60.     }
  61. }
  62.